<template>
    <div>
        <el-dialog v-model="state.isVisible" title="通知">
            <el-input type="textarea" v-model="state.chatContent" placeholder="Plase Input ChatContent" :rows="8"> </el-input>
            <el-button @click="sendMessage"> <Icon name="fa fa-send"></Icon>发送 </el-button>
        </el-dialog>
    </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'

import { sendUser, Message } from '/@/api/sys/message'
const state = reactive({
    isVisible: false,
    chatContent: '',
    onlineUser: {} as TableRow,
})
// 打开页面
const openDialog = (row: TableRow) => {
    state.chatContent = ''
    state.isVisible = true
    state.onlineUser = row
}
//发送通知
const sendMessage = () => {
    const userIds = new Array(state.onlineUser.userId)
    const msg: Message = {
        userIds: userIds,
        message: state.chatContent,
        title: '消息通知',
    }
    //发送消息跟指定人员
    sendUser(msg)
        .then((res) => {
            state.isVisible = false
        })
        .catch((err) => {
            console.log(err)
        })
}
defineExpose({
    openDialog,
})
</script>

<style scoped></style>
